<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <title>设置添加</title>
    <link th:href="@{/layui/css/layui.css}" rel="stylesheet"/>
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/jquery-3.3.1/jquery-3.3.1.js}"></script>
</head>

<body>
   <form class="layui-form"  th:action="@{/add}" th:object="${xixunSetting}" id="xixunSettingFrom"  method="post">

        <div class="layui-form-item" style="margin-top: 20px;">
            <label class="layui-form-label">IMEI：</label>
            <div class="layui-input-block">
                <input type="text" name="imei" id="imei"  style="width: 400px;"   placeholder="请输入imei"  class="layui-input">
            </div>
        </div>
       <div class="layui-form-item">
           <label class="layui-form-label">设置内容：</label>
           <div class="layui-input-block">
               <input type="text" name="setting" id="setting"  style="width: 400px;"  placeholder="请输入设置内容"  class="layui-input">
           </div>
       </div>
       <div class="layui-form-item">
           <label class="layui-form-label">消息ID：</label>
           <div class="layui-input-block">
               <input type="text" name="meg_id" id="meg_id"  style="width: 400px;"  placeholder="请输入消息ID内容"  class="layui-input">
           </div>
       </div>


       <div class="layui-form-item">
           <div class="layui-input-block">
               <button type="button" class="layui-btn"  th:onclick="'javascript:save()'">确认</button>
               <button type="reset" class="layui-btn layui-btn-primary">重置</button>
           </div>
       </div>
    </form>

</body>

<script>

    function save(){
        var imei = $("#imei").val();
        var setting = $("#setting").val();
        var meg_id = $("#meg_id").val();

        if(imei.trim()==""){
            parent.layer.msg("请输入imei号");
            return;
        }
        if(setting.trim()==""){
            parent.layer.msg("请输入设置内容");
            return;
        }
        if(meg_id.trim()==""){
            parent.layer.msg("请输入消息ID");
            return;
        }

        $.ajax({
            url: "/settingAdd",
            type: "POST",
            data:{"imei":imei,"setting":setting, "meg_id":meg_id},
            dataType: "json",
            success: function(data){
                if(data==1){
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);  // 关闭layer
                    parent.layer.msg("新增成功", {icon: 6});
                    parent.location.reload();
                }else{
                    parent.layer.msg("新增失败", {icon: 5});
                }
            }
        });
    }

</script>
</html>